// index.js
import {
  get,
  post,
  put
} from '../../utils/request'
import {
  APIS
} from '../../utils/api'
// 获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: {}
  },
  onShow() {
    const userInfo = wx.getStorageSync('userInfo');
    this.setData({
      userInfo
    });
  },
  getPhoneNumber(e) {
    const { code } = e.detail;
    const id = this.data.userInfo.id;
    put(`${APIS.user}/${id}`, { pCode: code }).then(res => {
      if (res.code === 0) {
        wx.setStorageSync('userInfo', res.data);
        wx.switchTab({
          url: '/pages/index/index'
        })
      }
    })
  },
  handleBackIndex() {
    wx.switchTab({
      url: '/pages/index/index'
    })
  },
  onShareAppMessage() {
    return getApp().globalData.shareMessage
  }
})